package com.example.myapplication;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChatHistoryActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_history);

        TextView textView = findViewById(R.id.person_name);
        ImageView imageView = findViewById(R.id.person_avatar);
        ListView listView = findViewById(R.id.chat_list_view);

        String personName = getIntent().getStringExtra("person_name");
        int imageId = getIntent().getIntExtra("image_id", R.drawable.dxx); // 默认头像

        textView.setText(personName);
        imageView.setImageResource(imageId); // 设置对应的头像

        List<Map<String, String>> chatRecords = getChatRecords(personName);
        SimpleAdapter adapter = new SimpleAdapter(this, chatRecords,
                R.layout.list_item_chat_history,
                new String[]{"message", "reply"},
                new int[]{R.id.message_text_view, R.id.reply_text_view});
        listView.setAdapter(adapter);
    }

    private List<Map<String, String>> getChatRecords(String personName) {
        List<Map<String, String>> chatRecords = new ArrayList<>();
        String message = "";

        switch (personName) {
            case "段坤":
                message = "我叫段坤，浪坤是我偶像。";
                break;
            case "浪坤":
                message = "我叫浪坤，刘坤是我偶像。";
                break;
            case "万坤":
                message = "我叫万坤，段坤是我偶像。";
                break;
            case "刘坤":
                message = "我叫刘坤，万坤是我偶像。";
                break;
        }

        Map<String, String> record = new HashMap<>();
        record.put("message", message);
        record.put("reply", "是的，中午去吃砂锅坤。"); // 添加回复
        chatRecords.add(record);

        return chatRecords;
    }
}